package com.goldcontrol.cloudweb.quartz.job;


import com.goldcontrol.cloudweb.model.JobEntity;
import com.goldcontrol.cloudweb.service.ScheduledService;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InitJob{

    private static final Logger LOGGER = LoggerFactory.getLogger(InitJob.class);

    @Autowired
    ScheduledService scheduledService;

    private static final Integer ACTIVE = 1;

    public void execute(){
        List<JobEntity> jobList = scheduledService.getActiveJobs(ACTIVE);
        for(JobEntity jobEntity : jobList){
            try{
                scheduledService.addQuartzJob(jobEntity);
            }catch (Exception e){
                LOGGER.error("初始化动态创建定时任务失败",e);
            }
        }
    }
}
